package com.yc.blog.dao.impl;

import java.util.List;

import com.yc.blog.bean.BlogType;
import com.yc.blog.dao.DBHelper;
import com.yc.blog.dao.IBlogTypeDao;

public class BlogTypeDaoImpl implements IBlogTypeDao {

	@Override
	public int add(String tname) {
		DBHelper db = new DBHelper();
		String sql = "insert into blogtype values(0,?,1)";
		return db.update(sql, tname);
	}

	@Override
	public int update(String tid, String status) {
		DBHelper db = new DBHelper();
		String sql = "update blogtype set status=? where tid =?";
		return db.update(sql, status,tid);
	}

	@Override
	public List<BlogType> findByPage(int page, int rows) {
		DBHelper db = new DBHelper();
		String sql = "select tid,tname,status from blogtype order by tid limit ?, ?";
		return db.finds(BlogType.class, sql, (page-1)*rows,rows);
	}

	@Override
	public int total() {
		DBHelper db = new DBHelper();
		String sql = "select count(tid) from blogtype";
		return db.total(sql);
	}

	@Override
	public List<BlogType> findAll() {
		DBHelper db = new DBHelper();
		String sql = "select tid,tname from blogtype where status !=0 order by tid";
		return db.finds(BlogType.class,sql);
	}

}
